You can customize the SeedCFill and CalcCMask procedures by writing your own color search function. For example, you might wish to use your own color search function to make SeedCFill generate a mask that allows filling around pixels that approximate the color of your seed point, rather than match it exactly.
The SeedCFill procedure generates a mask showing where the pixels in an image can be filled from a starting point, like the paint pouring from the MacPaint paint-bucket tool. The CalcCMask procedure generates a mask showing where pixels in an image cannot be filled from any of the outer edges of a rectangle you specify. You can then use these masks with the CopyBits , CopyMask , and CopyDeepMask procedures.
By default, SeedCFill returns 1's in the mask to indicate all pixels adjacent to a seed point whose colors do not exactly match the RGBColor record for the pixel at the seed point. By default, CalcCMask returns 1's in the mask to indicate what pixels have the exact RGB value that you specify in the seedRGB parameter, as well as which pixels are enclosed by shapes whose outlines consist entirely of pixels with this exact color. These procedures use a default color search function that matches exact colors.
You can customize these procedures by writing your own color search function and pointing to it in the matchProc parameters to these procedures, which then use your procedure instead of the default.
Here's how to declare a color search function to supply to the SeedCFill or CalcCMask procedure if you were to name the function MyColorSearch:
FUNCTION MyColorSearch (rgb: RGBColor;
position: LongInt): Boolean;
Your color search function should analyze the RGBColor record passed to it in the rgb parameter. To mask a pixel approximating that color, your color search function should return TRUE ; otherwise, it should return FALSE .
Your application should compare the RGBColor records that SeedCFill passes to your color search function against the RGBColor record for the pixel at the seed point you specify in that procedure's seedH and seedV parameters.
You can use a MatchRec record to determine the color of the seed pixel. When SeedCFill calls your color search function, the GDRefCon field of the current GDevice record (described in the chapter "Graphics Devices") contains a pointer to a MatchRec record that describes the seed point. This record has the following structure:
MatchRec =
RECORD
red: Integer; {red component of seed pixel}
green: Integer; {green component of seed pixel}
blue: Integer; {blue component of seed pixel}
matchData: LongInt; {value in matchData parameter of }
{ SeedCFill procedure}
END;
The matchData field contains whatever value you pass to SeedCFill in the matchData parameter. In the matchData parameter, for instance, your application could pass the handle to a color table. Your color search function could then check whether the color for the pixel currently under analysis matches any of the colors in the table.
Similarly, your application should compare the colors that CalcCMask passes to your color search function against the color that you specify in that procedure's seedRGB parameter. When CalcCMask calls your color search function, the GDRefCon field of the current GDevice record (described in the chapter "Graphics Devices") contains a pointer to a MatchRec record for your seed color. The matchData field of this record contains whatever value you pass to CalcCMask in the matchData parameter.